import axios from 'axios';
import env from '../config/env';

let util = {};

util.title = function(title) {
    title = title ? title + ' - Home' : 'iView project';
    window.document.title = title;
};

util.setcookie = function(name, value, expiredays) {
    let d = new Date()
    d.setDate(d.getDate() + expiredays)
    document.cookie = name + "=" + escape(value) +
        ((expiredays == null) ? "" : ";expires=" + d.toGMTString()) + ";path=/";
};

util.getcookie = function(name) {
    if (document.cookie.length > 0) {
        let start = document.cookie.indexOf(name + "=")
        if (start != -1) {
            start = start + name.length + 1;
            let end = document.cookie.indexOf(";", start);
            if (end == -1) end = document.cookie.length
            return unescape(document.cookie.substring(start, end));
        }
    }
    return "";
};

// const ajaxUrl = env === 'development' ?
//     'http://127.0.0.1:8888' :
//     env === 'production' ?
//     'https://www.url.com' :
//     'https://debug.url.com';

// util.ajax = axios.create({
//     baseURL: ajaxUrl,
//     timeout: 30000
// });

export default util;